import React from 'react';
import {
    Table,
} from 'antd';
import axios from 'axios';
import intercept from '../../utils/intercept';
import {config} from 'utils';
import moment from 'moment'

//订单详情组件
export default class InsuranceOrderList extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            loading: false,
            data: []
        };
    }

    componentDidMount() {
        this.getOrderdetail();
    };
    getOrderdetail() {
        const token = sessionStorage.getItem("token");
        this.setState({loading: true});
        const url = `${config.api}CustomService/GetInsuranceList?orderCode=${this.props.ordercode}`;
        axios
            .get(url,{headers:{Authorization:'Bearer ' + token}})
            .then((data) => {
                //console.log(data);
                this.setState({loading: false, data: data.data.insureList});
            })
            .catch(err => {
                intercept;
            })
    };
    render() {
        const statusstr = ['','投保成功','投保失败','','用户申请退款','用户申请退款成功','','','',''];
        const column = [
            {
                title: '保单号',
                dataIndex: 'insureCode',
                width: 150
            },
            {
                title: '参保人',
                dataIndex: 'name',
                width: 150
            }, {
                title: '身份证',
                dataIndex: 'cardId',
                width: 150
            }, {
                title: '受益人',
                dataIndex: 'beneficiaryName',
                width: 150
            },{
                title: '参保时间',
                dataIndex: 'validTime',
                width: 150,
                render:(text, record) => {
                    return(
                      <span>{record.validTime == null ? '':new moment(record.validTime).format('YYYY-MM-DD hh:mm')}</span>
                    )
                }
            },{
                title: '过期时间',
                dataIndex: 'expiryTime',
                width: 150,
                render:(text, record) => {
                    return(
                      <span>{record.expiryTime == null ? '':new moment(record.expiryTime).format('YYYY-MM-DD hh:mm')}</span>
                    )
                }
            },{
                title: '信息',
                dataIndex: 'message',
                width: 150
            }, {
                title: '状态',
                dataIndex: 'status',
                width: 150,
                render:(text, record) => {
                    return(
                      <span>{statusstr[record.status]}</span>
                    )
                }
            }
        ];
        return (<Table
            columns={column}
            rowClassName={() => {return 'childtable'}}
            dataSource={this.state.data}
            bordered={true}
            pagination={false}
            size="small"/>);
    }
}